package util

import Math._

class Complex(val real: Double, val imag: Double)
{
	def this() = this(0.0, 0.0)
 
	def mag = sqrt(real * real + imag * imag)
 
	def +(c: Complex) = new Complex(real + c.real, imag + c.imag)
 
	def *(c: Complex) = new Complex(real*c.real - imag*c.imag,
		real * c.imag + imag * c.real)
 
	override def toString() =
	{
		val prereal = if (real < 0) "-" else ""
		val preimag = if (imag < 0) "-" else "+"
		"%s%f%s%fi".format(prereal, abs(real), preimag, abs(imag))
	}
}

object Complex
{
	def apply() = new Complex()
  
	def apply(real: Double, imag: Double) = new Complex(real, imag)
}
